/*
 * @(#)IncomingRegistryObjects.java
 * Date 2013-09-13
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.registry.model;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import oasis.names.tc.ebxml_regrep.xsd.rim._3.AssociationType1;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ClassificationType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectRefType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-09-13
 * @author         Jim Horner
 */
public class IncomingRegistryObjects {

    /** Field description */
    private final Set<String> allids;

    /** Field description */
    private final Map<String, AssociationType1> associations;

    /** Field description */
    private final Map<String, ClassificationType> classifications;

    /** Field description */
    private final Map<String, ExtrinsicObjectType> documentEntries;

    /** Field description */
    private final Map<String, RegistryPackageType> folders;

    /** Field description */
    private final Map<String, String> identifiers;

    /** Field description */
    private final Map<String, ObjectRefType> objectRefs;

    /** Field description */
    private final Map<String, RegistryPackageType> registryPackages;

    /** Field description */
    private RegistryPackageType submissionSet;

    /**
     * Constructs ...
     *
     */
    public IncomingRegistryObjects() {

        super();

        this.allids = new HashSet<>();

        this.documentEntries = new HashMap<>();
        this.identifiers = new HashMap<>();
        this.registryPackages = new HashMap<>();
        this.associations = new HashMap<>();
        this.classifications = new HashMap<>();
        this.folders = new HashMap<>();
        this.objectRefs = new HashMap<>();
    }

    /**
     * Method description
     *
     *
     * @param assoctype
     */
    public void addAssociation(AssociationType1 assoctype) {

        this.associations.put(assoctype.getId(), assoctype);
    }

    /**
     * Method description
     *
     *
     * @param classtype
     */
    public void addClassification(ClassificationType classtype) {

        this.classifications.put(classtype.getId(), classtype);
    }

    /**
     * Method description
     *
     *
     * @param eo
     */
    public void addDocumentEntry(ExtrinsicObjectType eo) {

        this.documentEntries.put(eo.getId(), eo);
    }

    /**
     * Method description
     *
     *
     * @param regpack
     */
    public void addFolder(RegistryPackageType regpack) {

        this.folders.put(regpack.getId(), regpack);
    }

    /**
     * Method description
     *
     *
     * @param id
     */
    public void addIncomingId(String id) {

        this.allids.add(id);
    }

    /**
     * Method description
     *
     *
     * @param objectRefType
     */
    public void addObjectRef(ObjectRefType objectRefType) {

        this.objectRefs.put(objectRefType.getId(), objectRefType);
    }

    /**
     * Method description
     *
     *
     * @param regpack
     */
    public void addRegistryPackage(RegistryPackageType regpack) {

        this.registryPackages.put(regpack.getId(), regpack);
    }

    /**
     * Method description
     *
     *
     * @param oldId
     * @param newId
     */
    public void addTranslation(String oldId, String newId) {

        this.identifiers.put(oldId, newId);
    }

    /**
     * Method description
     *
     *
     * @param key
     *
     * @return
     */
    public RegistryPackageType findRegistryPackage(String key) {

        return this.registryPackages.get(key);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String[] getAssociationKeys() {

        Collection<String> result = this.associations.keySet();

        return result.toArray(new String[result.size()]);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public AssociationType1[] getAssociations() {

        Collection<AssociationType1> result = this.associations.values();

        return result.toArray(new AssociationType1[result.size()]);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public ClassificationType[] getClassifications() {

        Collection<ClassificationType> result = this.classifications.values();

        return result.toArray(new ClassificationType[result.size()]);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public ExtrinsicObjectType[] getDocumentEntries() {

        Collection<ExtrinsicObjectType> result = this.documentEntries.values();

        return result.toArray(new ExtrinsicObjectType[result.size()]);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public RegistryPackageType[] getFolders() {

        Collection<RegistryPackageType> result = this.folders.values();

        return result.toArray(new RegistryPackageType[result.size()]);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public ObjectRefType[] getObjectRefs() {

        Collection<ObjectRefType> result = this.objectRefs.values();

        return result.toArray(new ObjectRefType[result.size()]);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public RegistryPackageType getSubmissionSet() {

        return this.submissionSet;
    }

    /**
     * Method description
     *
     *
     * @param id
     *
     * @return
     */
    public boolean hasIncomingId(String id) {

        return this.allids.contains(id);
    }

    /**
     * Method description
     *
     *
     * @param regpack
     */
    public void setSubmissionSet(RegistryPackageType regpack) {

        this.submissionSet = regpack;
    }

    /**
     * Method description
     *
     *
     * @param oldId
     *
     * @return
     */
    public String translateId(String oldId) {

        return this.identifiers.get(oldId);
    }
}
